package com.pdg.dungeondelver.configuration;

import java.io.IOException;
import java.io.InputStream;
import org.newdawn.slick.util.ResourceLoader;

public class CQMFile {
	
	private byte[] cells = null;
	
	public byte getColumns(){
		return cells[0];
	}
	public byte getRows(){
		return cells[1];
	}
	public byte getCell(int column,int row){
		return cells[column+row*getColumns()];
	}

	public CQMFile(String content) throws CQMFileLoadException {
		if(!loadFile(content)){
			throw new CQMFileLoadException();
		}
	}

	private boolean loadFile(String content) {
		try {
			InputStream stream = ResourceLoader.getResourceAsStream(content);
			int columns = stream.read();
			int rows = stream.read();
			cells=new byte[2+columns*rows];
			cells[0]=(byte)columns;
			cells[1]=(byte)rows;
			stream.read(cells,2,columns*rows);
			return true;
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
	}

}
